<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let input=`4 3 5 7 8`
        input=input.split(' ')
        console.log(input);
        let t=null
        
        for(let i=0;i<input.length-1;i++){
            if(i%2===0){
                if(input[i]<input[i+1]){
                    t=input[i]
                    input[i]=input[i+1]
                    input[i+1]=t
                }
            }else{
                if(input[i]>input[i+1]){
                    t=input[i]
                    input[i]=input[i+1]
                    input[i+1]=t
                }

            }
        }
        
        console.log(...input);
        
        

    </script>
</body>
</html>